<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of v_fram2wav</title>
  <meta name="keywords" content="v_fram2wav">
  <meta name="description" content="V_FRAM2WAV  converts frame values to a continuous waveform [W]=(X,TT,MODE)">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">v_mfiles</a> &gt; v_fram2wav.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for v_mfiles&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>v_fram2wav
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>V_FRAM2WAV  converts frame values to a continuous waveform [W]=(X,TT,MODE)</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [w,s]=v_fram2wav(x,tt,mode) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment">V_FRAM2WAV  converts frame values to a continuous waveform [W]=(X,TT,MODE)
  Inputs:
          x(nf,p)      is the input signal: one row per frame
           tt(nf,3)     specifies the frames. Each row has the form [start_sample end_sample flag]
                       where flag = 1 for the start of a new spurt.
                       If tt(:,3) is omitted, a new spurt will be started whenever there is a gap
                       of more than one between the end of one frame and the beginning or the next.
                       A new spurt is automatically started if x() = NaN.
          mode         consists of one or more of the following letters:
                          z for zero-order hold interpolation (i.e. constant within each frame)
                          l for linear interpolation within each spurt [default]

 Outputs:
          w(n,p)       contains the interpolated waveforms. Their length is n = tt(nf,2)
          s(ns,2)      gives the starting and ending sample numbers of each spurt (excluding NaN spurts)

    This routine converts frame-based values to continuous waveforms by performing
    a chosen method of interpolation. Interpolation is restarted at the beginning of each spurt.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [w,s]=v_fram2wav(x,tt,mode)</a>
0002 <span class="comment">%V_FRAM2WAV  converts frame values to a continuous waveform [W]=(X,TT,MODE)</span>
0003 <span class="comment">%  Inputs:</span>
0004 <span class="comment">%          x(nf,p)      is the input signal: one row per frame</span>
0005 <span class="comment">%           tt(nf,3)     specifies the frames. Each row has the form [start_sample end_sample flag]</span>
0006 <span class="comment">%                       where flag = 1 for the start of a new spurt.</span>
0007 <span class="comment">%                       If tt(:,3) is omitted, a new spurt will be started whenever there is a gap</span>
0008 <span class="comment">%                       of more than one between the end of one frame and the beginning or the next.</span>
0009 <span class="comment">%                       A new spurt is automatically started if x() = NaN.</span>
0010 <span class="comment">%          mode         consists of one or more of the following letters:</span>
0011 <span class="comment">%                          z for zero-order hold interpolation (i.e. constant within each frame)</span>
0012 <span class="comment">%                          l for linear interpolation within each spurt [default]</span>
0013 <span class="comment">%</span>
0014 <span class="comment">% Outputs:</span>
0015 <span class="comment">%          w(n,p)       contains the interpolated waveforms. Their length is n = tt(nf,2)</span>
0016 <span class="comment">%          s(ns,2)      gives the starting and ending sample numbers of each spurt (excluding NaN spurts)</span>
0017 <span class="comment">%</span>
0018 <span class="comment">%    This routine converts frame-based values to continuous waveforms by performing</span>
0019 <span class="comment">%    a chosen method of interpolation. Interpolation is restarted at the beginning of each spurt.</span>
0020 
0021 <span class="comment">%    Bugs/Suggestions</span>
0022 <span class="comment">%      (1)   Additional mode option for cubic interpolation</span>
0023 <span class="comment">%      (2)   Additional mode option for interpolation in log domain</span>
0024 <span class="comment">%      (3)   Additional mode option for x values being</span>
0025 <span class="comment">%            frame averages rather than mid-frame values.</span>
0026 
0027 <span class="comment">%      Copyright (C) Mike Brookes 1997</span>
0028 <span class="comment">%      Version: $Id: v_fram2wav.m 10865 2018-09-21 17:22:45Z dmb $</span>
0029 <span class="comment">%</span>
0030 <span class="comment">%   VOICEBOX is a MATLAB toolbox for speech processing.</span>
0031 <span class="comment">%   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html</span>
0032 <span class="comment">%</span>
0033 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0034 <span class="comment">%   This program is free software; you can redistribute it and/or modify</span>
0035 <span class="comment">%   it under the terms of the GNU General Public License as published by</span>
0036 <span class="comment">%   the Free Software Foundation; either version 2 of the License, or</span>
0037 <span class="comment">%   (at your option) any later version.</span>
0038 <span class="comment">%</span>
0039 <span class="comment">%   This program is distributed in the hope that it will be useful,</span>
0040 <span class="comment">%   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
0041 <span class="comment">%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
0042 <span class="comment">%   GNU General Public License for more details.</span>
0043 <span class="comment">%</span>
0044 <span class="comment">%   You can obtain a copy of the GNU General Public License from</span>
0045 <span class="comment">%   http://www.gnu.org/copyleft/gpl.html or by writing to</span>
0046 <span class="comment">%   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.</span>
0047 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0048 
0049 <span class="keyword">if</span> nargin&lt;3
0050     mode=<span class="string">'l'</span>;
0051 <span class="keyword">end</span>
0052 [nf,m]=size(x);
0053 n=round(tt(<span class="keyword">end</span>,2));
0054 w=repmat(NaN,n,m);
0055 nt=size(tt,2);
0056 ix1=ceil(tt(:,1)); <span class="comment">% start of frame sample</span>
0057 ix2=floor(tt(:,2)); <span class="comment">% end of frame sample</span>
0058 
0059 <span class="comment">% determine the start and end of spurts</span>
0060 
0061 <span class="keyword">if</span> nt&gt;2
0062     ty=tt(:,3)&gt;0;   <span class="comment">% frame type set by user</span>
0063 <span class="keyword">else</span>
0064     ty=zeros(nf,1);
0065     ty(2:end)=ix1(2:end)&gt;ix2(1:end-1)+1;    <span class="comment">% new spurt whenever a gap</span>
0066 <span class="keyword">end</span>
0067 ty(1)=1;           <span class="comment">% first frame always starts a spurt</span>
0068 ty(isnan(x))=1;    <span class="comment">% NaN always ends previous spurt</span>
0069 ty(1+find(isnan(x(1:end-1))))=1; <span class="comment">% NaN always forces a new spurt</span>
0070 ty=double(ty);
0071 ty(1:end-1)=ty(1:end-1)+2*ty(2:end);
0072 ty(end)=ty(end)+2;   <span class="comment">% last frame always ends a spurtw=repmat(NaN,n,m);  % initialize output to all NaN</span>
0073 nx=ix2-ix1+1;
0074 
0075 <span class="keyword">if</span> any(mode==<span class="string">'z'</span>)   <span class="comment">% zero-order hold</span>
0076     <span class="keyword">for</span> i=1:nf
0077         <span class="keyword">if</span> nx(i)
0078             w(ix1(i):ix2(i),:)=repmat(x(i,:),nx(i),1);
0079         <span class="keyword">end</span>
0080     <span class="keyword">end</span>
0081 <span class="keyword">else</span>   <span class="comment">% linear interpolation is the default</span>
0082     ttm=(tt(:,1)+tt(:,2))/2;    <span class="comment">% mid point of frame</span>
0083     ixm=floor(ttm); <span class="comment">% end of first half of frame</span>
0084     <span class="keyword">for</span> i=1:nf
0085         <span class="keyword">if</span> i==176
0086             i
0087         <span class="keyword">end</span>
0088         <span class="keyword">if</span> nx(i)
0089             tyi=ty(i);
0090             <span class="keyword">if</span> tyi==3    <span class="comment">% use a zero order hold</span>
0091                 w(ix1(i):ix2(i),:)=repmat(x(i,:),nx(i),1);
0092             <span class="keyword">else</span>
0093                 nxm=ixm(i)-ix1(i)+1;
0094                 <span class="keyword">if</span> nxm
0095                     <span class="keyword">if</span> tyi==1    
0096                         grad=(x(i+1,:)-x(i,:))/(ttm(i+1)-ttm(i));
0097                     <span class="keyword">else</span>
0098                         grad=(x(i,:)-x(i-1,:))/(ttm(i)-ttm(i-1));    
0099                     <span class="keyword">end</span>
0100                     w(ix1(i):ixm(i),:)=repmat(x(i,:),nxm,1)+((ix1(i):ixm(i))'-ttm(i))*grad;
0101                 <span class="keyword">end</span>
0102                 <span class="keyword">if</span> nx(i)&gt;nxm
0103                     <span class="keyword">if</span> tyi==2
0104                         grad=(x(i,:)-x(i-1,:))/(ttm(i)-ttm(i-1));
0105                     <span class="keyword">else</span>
0106                         grad=(x(i+1,:)-x(i,:))/(ttm(i+1)-ttm(i));
0107                     <span class="keyword">end</span>
0108                     w(ixm(i)+1:ix2(i),:)=repmat(x(i,:),ix2(i)-ixm(i),1)+((ixm(i)+1:ix2(i))'-ttm(i))*grad;
0109                 <span class="keyword">end</span>
0110             <span class="keyword">end</span>
0111         <span class="keyword">end</span>
0112     <span class="keyword">end</span>
0113 <span class="keyword">end</span>
0114 
0115 <span class="comment">% now sort out the start and end spurt positions</span>
0116 
0117 ty(isnan(x))=0;    <span class="comment">% Don't count NaN spurts</span>
0118 s=repmat(ix1(bitand(ty,1)&gt;0),1,2);
0119 s(:,2)=ix2(bitand(ty,2)&gt;0);
0120 <span class="keyword">if</span> ~nargout
0121     tw=(1:n)';
0122     <span class="keyword">for</span> i=size(s,1):-1:2
0123         j=s(i,1);   <span class="comment">% start of new spurt</span>
0124         tw=[tw(1:j-1); tw(j); tw(j:end)];
0125         w=[w(1:j-1); NaN; w(j:end)];        <span class="comment">% insert a NaN to force a plotting break</span>
0126     <span class="keyword">end</span>
0127     plot(tt(:,1:2)',repmat(x(:)',2,1),<span class="string">'r-+'</span>,tw,w,<span class="string">'b-'</span>);
0128 <span class="keyword">end</span>
0129</pre></div>
<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>